package com.example.demo.config;

import com.example.demo.interceptor.AdminLoginInterceptor;
import com.example.demo.interceptor.UserLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @author shenrui
 * @date 2021/9/19
 * @description 继承WebMvcConfigurer，对拦截进行设置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * @description 拦截除了登录和注册页面之外的其他页面
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册admin拦截器
        registry.addInterceptor(new AdminLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/admin_login","/user_register","/user_login","/user_main","/user_logout","/user_game"
                                      ,"/to_user_game","/to_game_submit","/game_result","/to_game_record","/game_list");
        //注册user拦截器
        registry.addInterceptor(new UserLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/user_login","/user_register","/admin_login","/user_list","/admin_main","/admin_logout"
                                     ,"/user_delete/{id}","/user_revice_jump/{id}","/revice_user_info");

    }
}
